package com.itheima.domain;

import java.util.Objects;

/*
学生类
 */
public class Student /*implements Comparable<Student>*/ {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (age != student.age) return false;
        return name != null ? name.equals(student.name) : student.name == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + age;
        return result;
    }

    /**
     * 这是一个比较方法  让两个对象可以相互比较
     * int 结果
     * 负的 小 存 左边
     * 0  一样  不存
     * 正  大  存右边
     * <p>
     * this  代表着要插入的数据
     *
     * @param o 已经在集合中的数据
     * @return
     */
/*    @Override
    public int compareTo(Student o) {//this o


        //要存进去的是this
        //已经在里边的o

        //this -o  正序
        //o-this  倒叙
      *//*  System.out.println("this:" + this.name);
        System.out.println("o:" + o.name);*//*
        int result = o.age - this.age;
        result = result == 0 ? o.name.compareTo(this.name) : result;
        return result;
    }*/
}
